#include "KeyboardWidget.h"
#include "Widgets/WidgetTree.h"

RKeyboardWidget::RKeyboardWidget()
{
    Width=0;
    Height=0;
}

bool RKeyboardWidget::ProcessKeyboardEvent(const SKeyboardEvent &keyBoardEvent)
{
    if(OnKeyboardInput.IsBound())
    {
        return OnKeyboardInput.Execute(keyBoardEvent);
    }
    return false;
}

bool RKeyboardWidget::ProcessTextInput(const STextInputEvent & InTextInputEvent)
{
    if(OnTextInput.IsBound())
    {
        return OnTextInput.Execute(InTextInputEvent);
    }
    return false;
}

bool RKeyboardWidget::IsFocused() const
{
    if(!GetWidgetTree())
    {
        return false;
    }

    return GetWidgetTree()->IsFocused(this);
}

void RKeyboardWidget::ToggleFocus()
{
    if(IsFocused())
    {
        Unfocus();
    }
    else
    {
        Focus();
    }
}

void RKeyboardWidget::Focus()
{
    GetWidgetTree()->FocusWidget(this);
}

void RKeyboardWidget::Unfocus()
{
    if(!IsFocused())
    {
        return;
    }
    GetWidgetTree()->UnfocusWidget();
}

// void RKeyboardWidget::Focus()
// {
//     GetWidgetTree()->FocusWidget(this);
// }

// void RKeyboardWidget::Unfocus()
// {
//     GetWidgetTree()->Unfocus();
// }

void RKeyboardWidget::OnFocused()
{
    OnKeyboardFocused.ExecuteIfBound();
}

void RKeyboardWidget::OnUnfocused()
{
    OnKeyboardUnfocused.ExecuteIfBound();
}
